<template>
  <a-select
    :placeholder="placeholder"
    :value="value"
    @change="handleChange"
    :disabled="disabled"
    :mode="multiple ? 'multiple' : 'default'"
    :showSearch="true"
    :filterOption="filterOption">
    <a-select-option v-for="order in orderList" :key="order.id" :value="order.id">
      {{ order.orderCode }} - {{ order.orderName }}
    </a-select-option>
  </a-select>
</template>

<script>
  import { getAction } from '@/api/manage'

  export default {
    name: "JSelectOrder",
    props: {
      placeholder: {
        type: String,
        default: '请选择订单',
        required: false
      },
      value: {
        type: String,
        required: false
      },
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      multiple: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data() {
      return {
        orderList: []
      }
    },
    created() {
      this.loadOrderList()
    },
    methods: {
      loadOrderList() {
        getAction('/order/bOrderInfo/list', {pageSize: 100}).then((res) => {
          if (res.success) {
            this.orderList = res.result.records || []
          }
        })
      },
      handleChange(value) {
        this.$emit('change', value)
      },
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        )
      }
    }
  }
</script> 